﻿using Microsoft.Extensions.DependencyInjection;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;

namespace FlyingHat.Extensions.ServiceExtensions
{
    public static class JsonService
    {
        public static IMvcBuilder AddJsonService(this IMvcBuilder builder)
        {
            builder.AddNewtonsoftJson(i =>
            {
                // 日期类型默认格式化处理
                i.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
                // 首字母小写，即驼峰样式
                i.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
                // 日期类型默认格式化处理
                i.SerializerSettings.DateFormatString = "yyyy-MM-dd HH:mm:ss";
            });
            return builder;
        }
    }
}
